<div class="form wide">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
                'id' => 'packing-list-form',
                'enableAjaxValidation' => false,
            ));
    ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <div class="row">
        <?php echo CHtml::activeLabelEx($model['packing'], 'date'); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker',
                array(
                    'model' => $model['packing'],
                    'attribute' => "date",
                    'htmlOptions' => array('size' => 43, 'value' => (!empty($model['packing']->date)) ? (is_numeric($model['packing']->date)) ? date('d/m/Y', $model['packing']->date) : $model['packing']->date : date('d/m/Y')),
                    'options' => array('dateFormat' => 'dd/mm/yy'),
                )
        );
        ?>
<?php echo $form->error($model['packing'], 'date'); ?>
    </div>

    <div class="row">
<?php echo $form->labelEx($model['packing'], 'attn'); ?>
<?php echo $form->textField($model['packing'], 'attn', array('size' => 43, 'maxlength' => 50, 'placeholder' => 'In charge')); ?>
<?php echo $form->error($model['packing'], 'attn'); ?>
    </div>

    <div class="row">
<?php echo $form->labelEx($model['packing'], 'pol'); ?>
<?php echo $form->textField($model['packing'], 'pol', array('size' => 43, 'maxlength' => 150, 'placeholder' => 'Port of loading')); ?>
<?php echo $form->error($model['packing'], 'pol'); ?>
    </div>

    <div class="row">
<?php echo $form->labelEx($model['packing'], 'pod'); ?>
<?php echo $form->textField($model['packing'], 'pod', array('size' => 43, 'maxlength' => 150, 'placeholder' => 'Port of discharge')); ?>
<?php echo $form->error($model['packing'], 'pod'); ?>
    </div>

    <div class="row">
<?php echo CHtml::label($model['packing']->getAttributeLabel('handling_agent') . ' - ' . CHtml::link('Choose', '#', array('id' => 'Choose', 'panel_id' => 'handling')), 'handling_agent'); ?>
<?php echo $form->textField($model['packing'], 'handling_agent', array('size' => 43, 'data_id' => $model['packing']->handling_agent, 'disabled' => 'disabled', 'value'=>$model['packing']->handlingAgent->cname)); ?>
<?php echo $form->error($model['packing'], 'handling_agent'); ?>
    </div>

    <div class="row">
<?php echo CHtml::label($model['packing']->getAttributeLabel('clearing_agent') . ' - ' . CHtml::link('Choose', '#', array('id' => 'Choose', 'panel_id' => 'clearing')), 'clearing_agent'); ?>
<?php echo $form->textField($model['packing'], 'clearing_agent', array('size' => 43, 'data_id' => $model['packing']->clearing_agent, 'disabled' => 'disabled', 'value'=>$model['packing']->clearingAgent->cname)); ?>
<?php echo $form->error($model['packing'], 'clearing_agent'); ?>
    </div>

    <div class="row">
<?php echo CHtml::label($model['packing']->getAttributeLabel('notify_party') . ' - ' . CHtml::link('Choose', '#', array('id' => 'Choose', 'panel_id' => 'notify')), 'notify_party'); ?>
<?php echo $form->textField($model['packing'], 'notify_party', array('size' => 43, 'data_id' => $model['packing']->notify_party, 'disabled' => 'disabled', 'value'=>$model['packing']->notifyParty->cname)); ?>
<?php echo $form->error($model['packing'], 'notify_party'); ?>
    </div>

    <div class="row">
<?php echo CHtml::label($model['packing']->getAttributeLabel('shipping_line') . ' - ' . CHtml::link('Choose', '#', array('id' => 'Choose', 'panel_id' => 'shipping')), 'shipping_line'); ?>
<?php echo $form->textField($model['packing'], 'shipping_line', array('size' => 43, 'data_id' => $model['packing']->shipping_line, 'disabled' => 'disabled', 'value'=>$model['packing']->shippingLine->cname)); ?>
<?php echo $form->error($model['packing'], 'shipping_line'); ?>
    </div>

    <div class="row">
<?php echo $form->labelEx($model['packing'], 'subject'); ?>
<?php echo $form->textField($model['packing'], 'subject', array('size' => 43, 'maxlength' => 150, 'placeholder' => 'Packing list subject.')); ?>
<?php echo $form->error($model['packing'], 'subject'); ?>
    </div>

    <div class="row buttons">
        <?php
        $cancelUrl = Yii::app()->user->getReturnUrl();
        $this->widget('zii.widgets.jui.CJuiButton', array(
            'name' => 'submit',
            'caption' => 'Add info',
            'value' => "create",
        ));
        $this->widget('zii.widgets.jui.CJuiButton', array(
            'name' => 'cancel',
            'caption' => 'Cancel',
            'value' => "cancel",
            'buttonType' => 'button',
            'onclick' => "js:function(){window.location = '$cancelUrl';return false;}"
        ));
        ?>
        </div>

<?php $this->endWidget(); ?>

        </div>
<?php
    $cs = Yii::app()->getClientScript();
    $viewURL = CHtml::normalizeUrl(array('packing_list/view'));
    $companyURL = CHtml::normalizeUrl(array('company/showgrid'));
    $script = <<<EOD
$("#content").slideContent({width:'370'});
$.chooseToggler = '';
$.packing_list_create_form = {
	afterSubmit:function(data){
		window.location.href = "$viewURL?id="+data.id;
	}
};
$('#packing-list-form [type=submit]').click(function(){
	var params = [];
	var attrval = $('#packing_list_handling_agent').attr('data_id');
	var name = "packing_list[handling_agent]";
	if(attrval == undefined)
		params[name] = 0;
	else
		params[name] = attrval;
	
	var attrval = $('#packing_list_clearing_agent').attr('data_id');
	var name = "packing_list[clearing_agent]";
	if(attrval == undefined)
		params[name] = 0;
	else
		params[name] = attrval;
	
	var attrval = $('#packing_list_notify_party').attr('data_id');
	var name = "packing_list[notify_party]";
	if(attrval == undefined)
		params[name] = 0;
	else
		params[name] = attrval;
	
	var attrval = $('#packing_list_shipping_line').attr('data_id');
	var name = "packing_list[shipping_line]";
	if(attrval == undefined)
		params[name] = 0;
	else
		params[name] = attrval;
	
	var form = $.extend($.simplelogform,$.packing_list_create_form);
	form.Submit($('#packing-list-form'),params);
	return false;
});
$('a#Choose').click(function(){
        $(this).ToggleSlide('content','$companyURL',$(this).attr('slider_title'));
        $.chooseToggler = $(this).parent('label').next();
	return false;
});
$('a#choose_company').live('click',function(){
	var row = $(this).parents('tr').index();
	var id = $.fn.yiiGridView.getKey($(this).parents('.grid-view').attr('id'),row);
	var name = $(this).html();
	$.chooseToggler.val(name);
	$.chooseToggler.attr('data_id',id);
	return false;
});
EOD;
        $cs->registerScript('packing_list_create', $script);
?>